<template>
  <div>
    <div style="margin: 20px auto">
      <el-table v-if="data.songData.length" :data="data.songData">
        <el-table-column prop="name" label="名称" width="200" show-overflow-tooltip>
          <template v-slot="scope">
            <a :href="'/front/songDetail?id=' + scope.row.sing.id" style="color: #1357be">{{ scope.row.sing.name }}</a>
          </template>
        </el-table-column>
        <el-table-column prop="sing.composer" label="作曲人" show-overflow-tooltip></el-table-column>
        <el-table-column prop="sing.lyricist" label="作词人" show-overflow-tooltip></el-table-column>
        <el-table-column prop="" label="歌手" width="100">
          <template v-slot="scope">
            <img :src="scope.row.sing.singerAvatar" alt="" @click="router.push('/front/singerDetail?id=' + scope.row.sing.singerId)" style="width: 30px; height: 30px; border-radius: 50%; display: block; cursor: pointer">
          </template>
        </el-table-column>
        <el-table-column prop="sing.time" label="发行时间" show-overflow-tooltip></el-table-column>
        <el-table-column prop="" label="所属专辑" show-overflow-tooltip>
          <template v-slot="scope">
            <a :href="'/front/albumDetail?id=' + scope.row.sing.albumId + '&singerId=' + scope.row.sing.singerId" style="color: #1357be">《{{ scope.row.sing.albumName }}》</a>
          </template>
        </el-table-column>
        <el-table-column prop="sing.categoryName" label="所属分类" show-overflow-tooltip></el-table-column>
        <el-table-column prop="sing.duration" label="时长" show-overflow-tooltip></el-table-column>
        <el-table-column prop="" label="热度">
          <template v-slot="scope">🔥{{ scope.row.sing.hot }}</template>
        </el-table-column>
      </el-table>
      <div v-else style="margin-top: 100px; text-align: center; font-size: 15px; color: #666666">暂无收藏歌曲</div>
      <div v-if="data.total" style="margin-top: 50px">
        <el-pagination @current-change="loadSongCollect" layout="total,prev, pager, next" :page-size="data.pageSize" v-model:current-page="data.pageNum" :total="data.total"/>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from "vue";
import request from "@/utils/request.js";
import {ElMessage} from "element-plus";
import router from "@/router/index.js";

const data = reactive({
  user: JSON.parse(localStorage.getItem('xm-user') || '{}'),
  songData: [],
  total: 0,
  pageNum: 1,
  pageSize: 8,
})

const loadSongCollect = () => {
  request.get('/collect/selectPage', {
    params: {
      pageNum: data.pageNum,
      pageSize: data.pageSize,
      userId: data.user.id,
      type: 'SONG'
    }
  }).then(res => {
    if (res.code === '200') {
      data.songData = res.data?.list
      data.total = res.data?.total
    } else {
      ElMessage.error(res.msg)
    }
  })
}
loadSongCollect()

</script>